/*
 *  Copyright 2011 yura.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */

package org.opu.vcforms.bean.model;

import java.util.HashSet;
import java.util.Set;
import org.opu.vcforms.view.View;

/**
 *
 * @author yura
 */
public abstract class MultiViewModel<T extends View> {

    /** views of curent model */
    protected Set<T> views = new HashSet<T>();

    /**
     *  Return array with all views
     * @return array with all views
     */
    public abstract T[] viewsArray();

    /**
     *  Return number of views
     * @return number of views
     */
    public int viewsCount() {
        return views.size();
    }

    /**
     *  Remove all Views
     */
    public void removeAllViews() {
        views.clear();
    }

    /**
     *  Return true if view added. View can not be added
     * if it already exists in view collection
     * @param view new view
     * @return true if view added
     */
    public boolean addViews(T view) {
        return views.add(view);
    }

    /**
     * Repaint all views
     */
    public void repaint(){
        for (View v : views) {
            v.repaint();
        }
    }

    /**
     *  Reinit all data
     */
    public void reinit(){
        for (View v : views) {
            v.reinit();
        }
    }
}
